import http from 'kfz-utils/lib/http'
import api from './api'
import res from './res'
import req from './req'
import router from '@/router'
import axios from 'axios'
const apiConfig = {
    api,
    config: {
        // baseURL: 'http://192.168.1.110:8080/', // 刘丑新
        // baseURL: 'http://192.168.0.147:8080/', // 詹惠营
        baseURL: 'http://192.168.1.40:8089/', // 测试环境
        // baseURL: 'http://192.168.1.60:3000/', // mock
        // baseURL: 'https://admin2.shaguowenda.com/', // 正式环境
        timeout: 2e4, // 2000
        'Content-Type': 'application/x-www-form-urlencoded', // | 'application/x-www-form-urlencoded',
        mock: false
    }
}
const MOCK = null
const remote = apiConfig.config.baseURL
export default http({ apiConfig, MOCK, res, req })
export { remote }

axios.defaults.withCredentials = true

// token不存在则跳到登录
router.beforeEach((to, from, next) => {
    const token = localStorage.getItem('username') ? localStorage.getItem('username') : sessionStorage.username
    if (!token && to.path != '/login') {
        next({
            path: '/login'
        })
    } else {
        next()
    }
})
